

package top.continew.admin.controller.question;

import org.springframework.web.bind.annotation.*;
import top.continew.admin.question.manger.service.model.ExamPaperQuery;
import top.continew.admin.question.manger.service.ExamPaperService;
import top.continew.admin.question.manger.service.model.TestListVO;
import top.continew.starter.web.model.R;

import java.util.List;

/**
 * Created with Mac IntelliJ IDEA
 *
 * @Title: ExamPaperController
 * @Package: top.continew.question.controller
 * @Author: RHY
 * @Description:
 * @Date: 2020/3/3 09:39
 */
@RestController
@RequestMapping("examPaper")
public class ExamPaperController {

    private final ExamPaperService examPaperService;

    public ExamPaperController(ExamPaperService examPaperService) {
        this.examPaperService = examPaperService;
    }

    /**
     * 试卷上架查询接口
     *
     * @return
     *
     * @throws Exception
     */

    @PostMapping(value = "/list")
    public R list(@RequestBody ExamPaperQuery query) throws Exception {
        List<TestListVO> testList = examPaperService.getList(query);
        examPaperService.setTypeInfo(testList);
        return R.ok(testList);
    }

    /**
     * 试卷管理查询接口
     *
     * @return
     *
     * @throws Exception
     */

    @PostMapping(value = "/manager/list")
    public R managerList(@RequestBody ExamPaperQuery query) throws Exception {
        List<TestListVO> testList = examPaperService.getList(query);
        examPaperService.setTypeInfo(testList);
        return R.ok(testList);
    }

    /**
     * 试卷批量上线\下线接口
     *
     * @return
     *
     * @throws Exception
     */

    @PostMapping(value = "/onlineOrOffline")
    public R onlineOrOffline(@RequestParam(value = "paperId", required = true) String paperId,
                             @RequestParam(value = "type", required = true) int type) throws Exception {
        examPaperService.onlineOrOffline(paperId, type);
        return R.ok();
    }

    /**
     * 试卷导出接口
     *
     * @return
     *
     * @throws Exception
     */

    @GetMapping(value = "/export")
    public void export(@RequestParam(value = "paperId", required = true) Long paperId) throws Exception {
        examPaperService.export(paperId);
    }

}
